package userwashlogic

import (
	"context"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/service"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/pkg/xerrors"

	"gitee.com/liuxuezhan/ar-platform/assets-rpc/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/assets-rpc/rpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type UserWashLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewUserWashLogic(ctx context.Context, svcCtx *svc.ServiceContext) *UserWashLogic {
	return &UserWashLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *UserWashLogic) UserWash(in *rpc.UserWashRequest) (*rpc.UserWashResponse, error) {
	isOpen := service.NewUserWashService(l.ctx, l.svcCtx).IsOpenWash()
	if isOpen == 0 {
		return nil, xerrors.ErrUserWashNotOpened
	}

	err := service.NewUserWashService(l.ctx, l.svcCtx).DoUserWash(in.UserId, in.TypeName)
	if err != nil {
		return nil, err
	}
	return &rpc.UserWashResponse{}, nil
}
